{
LANG : PASCAL
PROB : sprime
}

program SPRIME;
const
  fi = 'sprime.in';
  fo = 'sprime.out';
  c : array[1..6] of byte = (1, 2, 3, 5, 7, 9);
  max = 10;
var
  d : array[1..max] of byte;
  p : array[1..10000] of integer;
  n, l : integer;

function prime(k : longint) : boolean;
var
  i, c : longint;
begin
  prime := false;
  if k = 1 then exit;
  c := trunc(sqrt(k));
  for i := 1 to l do
  begin
    if p[i] > c then break;
    if k mod p[i] = 0 then exit;
  end;
  prime := true;
end;

procedure init;
var
  i : longint;
begin
  l := 0;
  for i := 2 to 10000 do
    if prime(i) then
    begin
      inc(l);
      p[l] := i;
    end;
end;

procedure try(k : integer; s : longint);
var
  i, temp : longint;
  ok : boolean;
begin
  if k = n+1 then
  begin
    if prime(s) then writeln(s);
    exit;
  end;
  temp := s;
  for i := 1 to 6 do
  begin
    d[k] := c[i];
    s := s*10 + d[k];
    if prime(s) then try(k+1, s);
    s := temp;
  end;
end;

procedure process;
begin
  try(1, 0);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(n);
  init;
  process;
  close(output);
  close(input);
end.